package com.mowh.multithreading.future;

/**
 * @author mowh1gd
 * @create 2023/11/24 10:58
 */
public class Host {
    public Data request(final int count, final char c) {
        System.out.println("   request(" + count + ", " + c + ")  BEGIN");
        final FutureData future = new FutureData();//创建FutureData实例并由主线程直接返回该实例，同时开启新线程去生成数据（耗时）。
        new Thread() {
            @Override
            public void run() {
                RealData realData = new RealData(count, c);//生成数据RealData实例（耗时）
                future.setRealData(realData);//生成后给FutureData实例的realData属性赋值
            }
        }.start();
        System.out.println("   request(" + count + ", " + c + ")  END");
        return future;
    }
}
